﻿using System.Linq;
using System.Collections.Generic;

namespace Eugenhome.Atrium.Rss.Web
{
    /// <summary>
    /// 
    /// </summary>
    public class RssSourceItem
    {
        /// <summary></summary>
        private RssSource _rssSource { get; set; }
        /// <summary></summary>
        private RssCollection _rssCollection;

        /// <summary></summary>
        public string DisplayName { get { return string.Format("{0} ({1})", _rssSource.Name, _rssSource.Items.Count); } }

        /// <summary></summary>
        public int ID { get { return _rssSource.ID; } }

        /// <summary></summary>
        public string Name { get { return _rssSource.Name; } }

        /// <summary></summary>
        public string Link { get { return _rssSource.Url; } }

        /// <summary></summary>
        public List<RssItem> Items { get { return _rssSource.Items.Cast<Rss>().Select(item => new RssItem(item)).ToList(); } }


        /// <summary></summary>
        public bool Responsed { get { return _rssCollection!=null? _rssCollection.Responsed:false; } }

        /// <summary>
        ///  
        /// </summary>
        /// <param name="rssSource"></param>
        public RssSourceItem(RssSource rssSource)
        {
            _rssSource = rssSource;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns>Errors</returns>
        internal List<string> DataBind()
        {
            _rssCollection=_rssSource.DataBind(false, true);

            return _rssSource.Errors;
        }
    }
}